package com.lihao.sam.controller;

import com.lihao.sam.entity.Statistics;
import com.lihao.sam.service.intf.StatisticsService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Qinheyun
 * @Description:TODO
 */
@RestController
@RequestMapping("/api/sc/")
public class StatisticsController {
    @Resource
    private StatisticsService service;

    @PostMapping("add.do")
    public R add(Statistics statistics){
        return service.add(statistics);
    }

    @PostMapping("update.do")
    public R update(Statistics statistics){
        return service.update(statistics);
    }

    @PostMapping("del.do")
    public R del(int id){
        return service.del(id);
    }

    @GetMapping("page.do")
    public PageVo all(String campus, String storey, int page, int limit){
        return service.all(campus,storey,page,limit);
    }


    /**
     * 导入Excle*/
    @PostMapping("upload.do")
    public R upload(MultipartFile file) throws IOException {
        return service.importData(file);
    }

    /**
     * 导出xcle*/
    @GetMapping("download.do")
    public void downLoad(HttpServletResponse response) throws IOException {
        service.exportData(response);
    }

    @GetMapping("num.do")
    public PageVo querNum(int page, int limit){
        return service.quer(page, limit);
    }
}
